/*
 * sala.c
 *
 * Copyright (C) 2012 - Kellerman Rivero
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#include "sala.h"

Sala* Sala_Solicitar(){
	Sala* sala;
	sala = (Sala*)malloc(sizeof(sala));
	return sala;
}

Sala* Sala_Crear(unsigned int id, unsigned int capacidad, unsigned int *minELO, unsigned int *maxELO){
	Sala *sala = Sala_Solicitar ();
	if(sala!=NULL){
		sala->id=id;
		sala->capacidad=capacidad;

		if(minELO!=NULL){
			sala->minELO=*minELO;
		}else{
			sala->minELO=0;
		}
		
		if(maxELO!=NULL){
			sala->maxELO=*maxELO;
		}else{
			sala->maxELO=0;
		}

		sala->jugadores=NULL;
		sala->partidas=NULL;	
	}
	return sala;
}

Sala* Sala_RegistrarJugador(Sala* sala, Jugador* jugador){
	if((sala!=NULL) && (jugador!=NULL)){
		Lista* lista=(Lista*)sala->jugadores;
		sala=(Sala*)Lista_InsertarFinal (&lista,(void*)jugador);
	}
	return sala;
}

Sala* Sala_DesregistrarJugador(Sala* sala, Jugador* jugador, int *resultado){
	Criterio=NULL;
	if((sala!=NULL) && (jugador!=NULL)){
		Criterio=Jugador_Comparar;
		Lista_Eliminar ((Lista**)&sala,jugador,Criterio,resultado);
	}
	return sala;
}

void Sala_Imprimir(Sala* sala){
	if(sala!=NULL){
		printf("Sala:[%d -(%d)](%d-%d)\n",sala->id,sala->capacidad,sala->minELO,sala->maxELO);
	}else printf("Vacio\n");
}


